package com.imooc.o2o.web;

import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/superadmin")
public class AreaController {
    @Autowired
    private AreaService areaService;
    Logger logger =LoggerFactory.getLogger(AreaController.class);
    @ResponseBody
    @RequestMapping(value = "/listarea",method = RequestMethod.GET)
    public Map<String,Object> getAreaList() {
        logger.info("====start===");
        long startTime=System.currentTimeMillis();
        Map<String, Object> m = new HashMap<>();
        List<Area> arealist =null;
        try {
            arealist = areaService.getAreaList();
            m.put("row",arealist);
            m.put("success","true");
        }catch (Exception e){
            e.printStackTrace();
            m.put("success","false");
            m.put("error",e);
        }
        logger.error("test error");
        long endTime=System.currentTimeMillis();
        logger.debug("costTime:[{}ms]",endTime-startTime);
        logger.info("====end===");
        return m;
    }
}
